package com.reqresp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author wzm
 * @create 2023-09-20 9:28
 * project_name:javaweb2308
 */
@WebServlet("/resp01")
public class RespServlet01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("我不处理这个事情了，你去找xxx吧");
        //设置响应状态码
       // resp.setStatus(302);//当前请求重定向

        //设置响应头  设置与重定向一起使用重新访问的地址
        //Location:地址
       //resp.setHeader("Location",req.getContextPath()+"/resp302");

        req.setAttribute("a","dddd");
        //resp.sendRedirect(req.getContextPath()+"/resp302");
//        resp.sendRedirect(req.getContextPath()+"/WEB-INF/index.jsp");
        resp.sendRedirect("http://www.baidu.com");

    }
}
